import service from "../service";
import appModal from "../components/appModal";

import { mapGetters } from 'vuex'

export default  {
  template: "#" + "maintpl",
  components: {
    appModal
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  data() {
    return {
      dirs: [],
      cur: {}
    }
  },
  mounted() {
    this.fetchData()
    window.baseFolder = 'D:\\projects\\pixiv'
  },
  watch: {
    $route() {
      this.fetchData()
    }
  },
  methods: {
    async fetchData() {
      let res = await service.get('/api/listfile', {
        params: {
          folder: decodeURIComponent( this.$route.params.folder )
        }
      })
      console.log(res.data.data.dirs)
      this.$set(this, 'dirs', res.data.data.dirs)
    },
    async parseDir(type = '', path = '', dir) {
      this.cur = dir
      if (type === 'file') {
        this.getFileStatus(path)
      } else {
        let folder = this.$route.params.folder
        // location.search = `?folder=${encodeURI(encodeURI(path))}`
        // this.$route.params.folder = encodeURI(encodeURI(path))
        this.$router.push({
          name: 'Index',
          params: {
            folder: encodeURI(encodeURI(path))
          }
        })
        // console.log(this.$route)
        // location.href = window.location.origin + window.location.pathname + "#" + this.$route.meta.path.replace(':folder', encodeURI(encodeURI(path)))
      }
    },
    async getFileStatus(dir) {
      let res = await service.get('/api/filestatus', {
        params: {
          filepath: dir
        }
      })
      // console.log(res.data.data)

      this.$refs.appModal.show('video-modal', dir, res.data.data)
    }
  }
}
